import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type WorkflowTemplateDocument = WorkflowTemplate & Document;

@Schema()
class WorkflowStats {
    @Prop({ default: 0 })
    uses: number;

    @Prop({ default: 0 })
    likes: number;

    @Prop({ default: 0 })
    views: number;
}

@Schema({ timestamps: true })
export class WorkflowTemplate {
    @Prop({ required: true })
    name: string;

    @Prop()
    description?: string;

    @Prop({ default: 'anonymous' })
    author: string;

    @Prop({ required: true })
    category: string;

    @Prop({ required: true })
    thumbnail: string;

    @Prop({ type: Object, required: true })
    comfyuiJson: Record<string, any>;

    @Prop({ type: [String], default: [] })
    tags: string[];

    @Prop({ default: false })
    isPublic: boolean;

    @Prop({ default: '1.0.0' })
    version: string;

    @Prop({
        type: WorkflowStats, default: () => ({
            uses: 0,
            likes: 0,
            views: 0
        })
    })
    stats: WorkflowStats;

    @Prop({ type: Date, default: Date.now })
    createTime: Date;

    @Prop({ type: Date, default: Date.now })
    updateTime: Date;
}

export const WorkflowTemplateSchema = SchemaFactory.createForClass(WorkflowTemplate); 